
/**
 * @Title: GsjzrqCheck.java
 * @Package com.py.credit.clean.code
 * @Description: TODO
 * Copyright: Copyright (c) 2020
 * Company:金电联行(江苏)信息技术有限公司
 * @author Comsys-jdzc
 * @date 2020年8月14日 下午3:14:38
 * @version V1.0
 */

package com.py.credit.clean.code;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.util.CollectionUtils;

/**
 * @ClassName: GsjzrqCheck
 * @Description: TODO(公示截至日期校验)
 * @author jdzc
 * @date 2020年8月14日 下午3:14:38
 *
 */

public class GsjzrqCheck {

	public static boolean run(Map<String, Object> map, String extend) {
		String GSJZRQ = String.valueOf(map.get("CF_GSJZQ"));
		String CFJDRQ = String.valueOf(map.get("CF_JDRQ"));
		Calendar cal = Calendar.getInstance();

		try {
			
			
		if(CFJDRQ.contains("/")) {
		
			Date JZRQ = sfdate(GSJZRQ);
			Date date = sfdate(CFJDRQ);
			String[] str = CFJDRQ.split("/");
			int month = date.getMonth();
			int day = Integer.valueOf(str[2]);
			if(month==2 && day == 29) {
				cal.setTime(date);	
				cal.add(Calendar.YEAR, 1);
				cal.add(Calendar.DAY_OF_MONTH, -1);
				if(JZRQ.compareTo(cal.getTime()) == 0) {
					return true;
				}else {
					cal.add(Calendar.YEAR, 2);
					if (JZRQ.compareTo(cal.getTime()) == 0) {
						return true;
					} else {
						return false;
					}
				}
			}else {
				cal.setTime(date);	
				cal.add(Calendar.YEAR, 1);
				if(JZRQ.compareTo(cal.getTime()) == 0) {
					return true;
				}else {
					cal.add(Calendar.YEAR, 2);
					if (JZRQ.compareTo(cal.getTime()) == 0) {
						return true;
					} else {
						return false;
					}
				}
			}
			
		}else {
		
			Date JZRQ = sfdate(GSJZRQ);
			Date date = sfdate(CFJDRQ);
			String[] str = CFJDRQ.split("-");
			int month = date.getMonth();
			int day = Integer.valueOf(str[2]);
			if(month==2 && day == 29) {
				cal.setTime(date);	
				cal.add(Calendar.YEAR, 1);
				cal.add(Calendar.DAY_OF_MONTH, -1);
				System.out.println(cal.getTime());
				if(JZRQ.compareTo(cal.getTime()) == 0) {
					return true;
				}else {
					cal.add(Calendar.YEAR, 2);
					if (JZRQ.compareTo(cal.getTime()) == 0) {
						return true;
					} else {
						return false;
					}
				}
			}else {
				cal.setTime(date);	
				cal.add(Calendar.YEAR, 1);
				if(JZRQ.compareTo(cal.getTime()) == 0) {
					return true;
				}else {
					cal.add(Calendar.YEAR, 2);
					if (JZRQ.compareTo(cal.getTime()) == 0) {
						return true;
					} else {
						return false;
					}
				}
			}
		
			
		}
		

		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		return false;

	}
	
	public static Date sfdate (String data) {
		Date date = null ;
		try {
		if(data.contains("-")) {
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		
				 date = sf.parse(data);
			
		}else {
			SimpleDateFormat sf = new SimpleDateFormat("yyyy/MM/dd");
			
			date	= sf.parse(data);
		}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return date;
		
	}

	public static void main(String[] args) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("CF_GSJZQ", "2023-02-28");
		map.put("CF_JDRQ", "2022/02/29");
		if (run(map, "")) {
			System.out.println("true");
		} else {
			System.out.println("false");
		}

	}
}
